import java.util.StringTokenizer;

class P10908_39643 {

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

	public static void main(String[] args) {
		
		int cases = Integer.parseInt(readLn());

		try {
		
		for (int k = 0; k < cases; k++) {
			process();
		}	
		} catch (Exception e) {
			while (true) {
				
			}
		}
	}

	private static void process() {
		StringTokenizer st = new StringTokenizer(readLn());
		
		int m = Integer.parseInt(st.nextToken());
		int n = Integer.parseInt(st.nextToken());
		int q = Integer.parseInt(st.nextToken());
		
		System.out.println(m + " " + n + " " + q);
		
		char[][] table = new char[m][n];
		
		for (int k = 0; k < m; k++) {
			
			String line = readLn();
			
			for (int j = 0; j < n; j++) {
				table[k][j] = line.charAt(j);
			}
			
		}
		
		
		for (int k = 0; k < q; k++) {
			st = new StringTokenizer(readLn());
			
			int r = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			
			if (!(r >= 0 && r < m && c >= 0 && c <= n)) {
				System.out.println(0);
				continue;
			}
				
			
			char x = table[r][c];
			
			int counter = 0;
			
			while (canExpand(table, r, c, x, counter, m, n)) {
				counter++;
			}
			
			int solution = 1 + 2 * counter;
			
			System.out.println(solution);
			
		}
		
	}

	private static boolean canExpand(char[][] table, int r, int c, char x, int counter, int m, int n) {
		
		counter++;
		
		if (!(r + counter < m && r - counter >= 0 && c + counter < n && c - counter >= 0))
			return false;
		
		for (int k = r - counter; k <= r + counter; k++) {
			if (table[k][c + counter] != x) return false;
			if (table[k][c - counter] != x) return false;
		}
		
		for (int k = c - counter; k <= c + counter; k++) {
			if (table[r + counter][k] != x) return false;
			if (table[r - counter][k] != x) return false;
		}
		
		return true;
	}

		
}
